package com.drivers.homepage.listener;




import com.drivers.homepage.domain.OrderInformation;
import com.drivers.homepage.mapper.OrderInformationMapper;
import com.rabbitmq.client.Channel;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


/**
 *
 * @Author zhaomingshuo
 * @Date: 2024/09/01
 */
@Component
@Slf4j
public class PayLister {

    @Autowired
    OrderInformationMapper orderInformationMapper;


    @RabbitListener(queuesToDeclare = @Queue("ruoyiqueue"))
    @RabbitHandler
    public String testConsumer(OrderInformation orderInformation, Channel channel, Message message) throws Exception {
        log.info("orderInformation消费消息:{}", orderInformation);

//        order.setPaymenttime(LocalDateTime.now());
//
//        cartMapper.updateorder(order);
        log.info("获取成功!");

        /**
         * ACK，用的最多的一种
         * deliveryTag:该消息的index
         * false:表示不是批量
         */
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        log.info("order消费消息成功");

        return "消费-result";
    }
}
